<?php
require_once 'TaskProgress.php';

class TaskTimerAfterProgress extends TaskProgress
{
    /**
     * @var int 秒数
     */
    protected $seconds = 1;

    /**设置任务秒数后执行
     * @param int $seconds 秒数
     * @return $this
     */
    public function setSecondAfter(int $seconds = 1)
    {
        if ($seconds <= 0) $seconds = 1;
        $this->seconds = $seconds;
        return $this;
    }

    /**获取毫秒级数
     * @return float|int
     */
    public function getMillisecond()
    {
        return $this->seconds * 1000;
    }

    /**定义做任务的闭包执行
     * @param \Swoole\Process $process
     */
    protected function doTaskCallable(\Swoole\Process &$process)
    {
        \Swoole\Timer::after($this->getMillisecond(), function() use ($process) {
            parent::doTaskCallable($process);
        });
    }
}




